package com.shengwei.truck.driver.view.adapter.task;
import android.content.Context;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import com.shengwei.truck.driver.R;
import com.shengwei.truck.driver.view.ui.task.TaskListFragment;
/*
 * 任务列表的ViewPager for Fragment
 */
public class TaskFragmentPagerAdapter extends FragmentPagerAdapter {
    private final Context mContext;
    @StringRes public static final int[] TAB_TITLES = new int[]{R.string.new_order,R.string.new_task, R.string.has_complete,R.string.has_forward};

    public TaskFragmentPagerAdapter(Context context,FragmentManager fm) {
        super(fm);
        mContext = context;
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return mContext.getResources().getString(TAB_TITLES[position]);
    }

    @Override
    public int getCount() {
        return TAB_TITLES.length;
    }


    @Override
    public Fragment getItem(int tabIndex) {
        // 后台任务状态：0未接单 1接单 2提货-运输 3榜单 4重新提交榜单 5完成 6提货超时 7撤销 8任务过期
        int taskState = -1;
        int isForward = 0; //是否转派，1转派
        switch (tabIndex) {
            case 0:
                taskState = 9;  //这个是app客户端自定义的状态，用于区分其它任务状态
                break;
            case 1:            //新任务
                taskState = 0;
                break;
            case 2:            //已完成
                taskState = 5;
                break;
            case 3:           //转派列表，不用传递状态
                taskState = -1;
                isForward = 1;
                break;
        }
        Fragment fragment =  TaskListFragment.newInstance(taskState,isForward);
        return fragment;
    }

    @Override
    public int getItemPosition(Object object) {
        return super.getItemPosition(object);
    }

}
